﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using DecisionFramework.Instrument;

namespace DecisionFramework.Logging
{
    /// <summary>
    /// Provides a publish policy for instrumentation that returns true for 
    /// ShouldPublish() if an hour has passed since the last it was published
    /// or started.  
    /// </summary>
    /// <remarks>  
    /// Author: Greg Cowin
    /// </remarks> 
	public class LogServiceInstrumentationReportPolicy : IPublishPolicy
	{
        /// <summary>
        /// Whether it is time to report on the instrumentation. In this policy,
        /// it will report if an hour has passed since the last time it was
        /// published or started.
        /// </summary>
        /// <returns> Whether it is time to report on the instrumentation.</returns>
		public bool ShouldPublish(Instrumentation instrumentation)
		{
			TimeSpan howLongHasItBeen = new TimeSpan(DateTime.UtcNow.Ticks - instrumentation.LastReportTimeUtc.Ticks);
			return howLongHasItBeen >= new TimeSpan(1 * TimeSpan.TicksPerHour);	
		}
	}
}
